import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class MyDevice extends StatefulWidget{
  MyDeviceState createState()=>MyDeviceState();
}

class MyDeviceState extends State<MyDevice>{
  List device=new List<Device>();
  void getDevice(){
    Device device_phone=new Device(true, true, "我是一部手机");
    Device device_pc=new Device(false,true,"我是一台电脑");
    device.add(device_phone);
    device.add(device_pc);
    device.add(device_phone);
    device.add(device_pc);
    device.add(device_phone);
    device.add(device_pc);
  }
  initState(){
    getDevice();
  }
  Widget build(BuildContext context){
    return Scaffold(
      appBar: new AppBar(
        title: Text('我的设备'),
      ),
      body: Container(
        child: ListView.builder(
          itemCount: 5,
          itemBuilder: (BuildContext context,int position){
            return ListTile(
              title: Text(device.elementAt(position).model),
              leading: Icon(device.elementAt(position).isPhone?Icons.phone_android:Icons.ondemand_video),
              trailing: Icon(Icons.check,color:device.elementAt(position).isThis?Colors.red:Colors.white ,),
            );
        }),
      ),
    );
  }
}

class Device{
  String model;
  bool isThis;
  bool isPhone;
  Device(this.isPhone,this.isThis,this.model);
}